package com.tian.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tian.dao.entity.Menu;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * {@code @description:} 用户信息mapper
 *
 * @author tianwc 公众号：Java后端技术全栈
 * 在线刷题 1200+java面试题和1000+篇技术文章：<a href="https://woaijava.cc/">博客地址</a>
 * {@code @date:} 2024-07-28 12:02
 * {@code @version:} 1.0
 */
public interface MenuMapper extends BaseMapper<Menu> {

    @Select("SELECT m.id, m.menu_name, m.menu_url, m.icon, m.parent_id, m.menu_order,m.permission_flag,m.opt_type\n" +
            "FROM tb_menu m\n" +
            "JOIN (\n" +
            "    SELECT menu_name, parent_id, MIN(id) AS min_id\n" +
            "    FROM tb_menu\n" +
            "    WHERE parent_id =  #{parentId} \n" +
            "    GROUP BY menu_name, parent_id\n" +
            ") AS sub ON m.id = sub.min_id\n" +
            "WHERE m.parent_id = #{parentId}")
    List<Menu> selectByUserInfo(Integer parentId);
}
